/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject4g1.web.action;

import com.opensymphony.xwork2.ModelDriven;
import eproject.ejb.entity.Users;
import eproject.ejb.session.UsersFacadeLocal;
import eproject4g1.configuration.EnviroimentVariable;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author khiemtd
 */
public class UserAction extends ActionConfig implements ModelDriven<Users> {

    /**
     * Attributes
     */
    @EJB
    private UsersFacadeLocal usersFacadeLocal;
    private Users user = new Users();

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }

    public UserAction() {
    }

    /**
     * Get users
     *
     * @return 
     */
    public String getUsers() {
        /*
         Local vairable declaration
         */
        List<Users> lstUsers;
        try {
            /* Call enterprise bean */
            this.usersFacadeLocal = (UsersFacadeLocal) this.ejb3LookupBean("java:comp/env/UsersFacade");
            lstUsers = this.usersFacadeLocal.findAll();
            System.out.println("Users= "+lstUsers.size());
            this.httpSession.setAttribute(EnviroimentVariable.USERS, lstUsers);
            return SUCCESS;
        } catch (NamingException ne) {
            ne.printStackTrace();
            return ERROR;
        }
    }

    public Users getModel() {
        return this.user;
    }
}
